<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                        <el-button type="danger" class="butT" @click="handleDeleteSelection()">删除选中</el-button>
                    </div>
                    <!--遍历展示的表格-->
                    <el-table size="small" current-row-key="id" :data="dataList" @selection-change="handleSelectionChange" stripe highlight-current-row >
                        <el-table-column type="selection" width="55"></el-table-column>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                        <el-table-column prop="member.fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column prop="member.name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="member.phoneNumber" label="手机号" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>

                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleConfirm(scope.row)">确定预约</el-button>
                                <br>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <!--分页栏-->
                    <div class="pagination-container">
                        <el-pagination
                                background
                                class="pagiantion"
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                :page-sizes="[10,15,20]"
                                layout="sizes, total, prev, pager, next, jumper"
                                :total="pagination.total">
                            <!--:page-size="pagination.pageSize"-->
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" width="800px" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px" ref="formData" :model="formData" :rules="rules">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名" prop="name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证">
                                                        <el-input v-model="formData.idCard"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                placeholder="选择您的出生日期"
                                                                type="date" style="height: 30px">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号">
                                                        <el-input v-model="formData.telephone"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别" prop="sex">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="年龄" prop="age">
                                                        <el-input v-model="formData.age"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约时间">
                                                        <el-date-picker
                                                                v-model="formData.orderDate"
                                                                placeholder="选择您要预约的日期"
                                                                type="date" style="height: 30px">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="邮箱">
                                                        <el-input v-model="formData.email"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <!--搜索框-->
                                        <el-input placeholder="名称/编码/助记码" v-model="setmeal_pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                                        <el-button @click="findSetmeal()" class="dalfBut">查询</el-button>
                                        <!--套餐信息-->
                                        <div class="checkScrol">

                                            <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" @row-click="chooseRow" @current-change="changeChooseRow" highlight-current-row >
                                                <el-table-column width="50">
                                                    <template scope="scope">
                                                        <el-radio v-model="radio" :label="scope.$index">&nbsp;</el-radio>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column prop="name" label="套餐名称" width="120">
                                                </el-table-column>
                                                <el-table-column prop="code" label="套餐编码" width="120">
                                                </el-table-column>
                                                <el-table-column prop="helpCode" label="套餐助记码" width="120">
                                                </el-table-column>
                                                <el-table-column prop="remark" label="套餐介绍" show-overflow-tooltip>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                        <div class="pagination-container">
                                            <el-pagination
                                                    background
                                                    class="pagiantion"
                                                    @size-change="setmealHandleSizeChange"
                                                    @current-change="setmealHandleCurrentChange"
                                                    :current-page="setmeal_pagination.currentPage"
                                                    :page-size="setmeal_pagination.pageSize"
                                                    :page-sizes="[8,10,12]"
                                                    layout="sizes, prev, pager, next, jumper"
                                                    :total="setmeal_pagination.total">
                                            </el-pagination>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">保存</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑预约" width="800px" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px" ref="dataEditForm" :model="formData" :rules="rules">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名" prop="name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证">
                                                        <el-input v-model="formData.idCard"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                placeholder="选择您的出生日期"
                                                                type="date" style="height: 30px">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号">
                                                        <el-input v-model="formData.telephone"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别" prop="sex">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="年龄" prop="age">
                                                        <el-input v-model="formData.age"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约时间">
                                                        <el-date-picker
                                                                v-model="formData.orderDate"
                                                                placeholder="选择您要预约的日期"
                                                                type="date" style="height: 30px">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="邮箱">
                                                        <el-input v-model="formData.email"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <!--搜索框-->
                                        <el-input placeholder="名称/编码/助记码" v-model="setmeal_pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                                        <el-button @click="findSetmeal()" class="dalfBut">查询</el-button>
                                        <!--套餐信息-->
                                        <div class="checkScrol">

                                            <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" @row-click="chooseRow" @current-change="changeChooseRow" highlight-current-row >
                                                <el-table-column width="50">
                                                    <template scope="scope">
                                                        <el-radio v-model="radio" :label="scope.$index">&nbsp;</el-radio>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column prop="name" label="套餐名称" width="120">
                                                </el-table-column>
                                                <el-table-column prop="code" label="套餐编码" width="120">
                                                </el-table-column>
                                                <el-table-column prop="helpCode" label="套餐助记码" width="120">
                                                </el-table-column>
                                                <el-table-column prop="remark" label="套餐介绍" show-overflow-tooltip>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                        <div class="pagination-container">
                                            <el-pagination
                                                    background
                                                    class="pagiantion"
                                                    @size-change="setmealHandleSizeChange"
                                                    @current-change="setmealHandleCurrentChange"
                                                    :current-page="setmeal_pagination.currentPage"
                                                    :page-size="setmeal_pagination.pageSize"
                                                    :page-sizes="[8,10,12]"
                                                    layout="sizes, prev, pager, next, jumper"
                                                    :total="setmeal_pagination.total">
                                            </el-pagination>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        new Vue({
            el: '#app',
            data:{
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:100,//总记录数
					  queryString:null//查询条件
				},
                setmeal_pagination: {//分页相关模型数据
                    currentPage: 1,//当前页码
                    pageSize:10,//每页显示的记录数
                    total:100,//总记录数
                    queryString:null//查询条件
                },
                radio: '',
                activeName:'first',
				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                tableData:[],//增加表单选项卡中展示的所有套餐数据
                setmealId:"",//被选中的体检套餐id
                orders:[],
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit:false,//编辑表单是否可见
                rules: {//校验规则
                    name: [{ required: true, message: '姓名为必填项', trigger: 'blur' }],
                    sex: [{ required: true, message: '性别为必填项', trigger: 'blur' }],
                    age: [{ required: true, message: '年龄为必填项', trigger: 'blur' }]
                },
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
            },
            methods: {
                //编辑
                handleEdit() {
                },
                //添加
                handleAdd () {
                    //先进行表单校验,再关闭添加窗口
                    this.$refs['formData'].validate((valid)=>{
                        if (valid){
                            axios.post("/ordersettinglist/add.do?setmealId="+this.setmealId,this.formData).then((resp)=>{
                                if (resp.data.flag){
                                    this.dialogFormVisible = false;
                                    this.$message.success(resp.data.message);
                                }else
                                    this.$message.error(resp.data.message);
                            }).catch((error)=>{
                                console.log(error);
                            }).finally(()=>{
                                this.findPage();
                            })
                        } else {
                            //表单校验失败,提示用户输入的信息有误
                            this.$message.error("您输入的信息有误");
                        }
                    })

                },
                //分页查询
                findPage() {
                    //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                    var param = {
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString: this.pagination.queryString
                    };
                    axios.post("/ordersettinglist/findPage.do",param).then((res)=>{
                        if (res.data.flag){
                            //解析Controller响应回的数据，为模型数据赋值
                            this.pagination.total = res.data.data.total;
                            this.dataList = res.data.data.rows;
                        } else {
                            this.$message.error(res.data.message);
                        }
                    }).catch((error)=>{
                        console.log(error);
                    });
                },
                //查找套餐信息
                findSetmeal(){
                    var param = {
                        currentPage:this.setmeal_pagination.currentPage,
                        pageSize:this.setmeal_pagination.pageSize,
                        queryString: this.setmeal_pagination.queryString
                    };
                    axios.post("/setmeal/findPage.do",param).then((resp)=>{
                        this.tableData = resp.data.rows;
                        this.setmeal_pagination.total = resp.data.total;
                    }).catch((error)=>{
                        console.log(error);
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData = {};//重置数据
                },
                // 弹出添加窗口
                handleCreate() {
                    this.resetForm();
                    this.dialogFormVisible = true;
                    this.activeName = "first";
                    this.setmealId = "";
                    this.radio = "";
                    this.setmeal_pagination.currentPage = 1;
                    this.setmeal_pagination.pageSize = 10;
                    this.setmeal_pagination.total = 100;
                    this.setmeal_pagination.queryString = null;
                    this.findSetmeal();
                },
                //确认预约
                handleConfirm(row) {
                    axios.post("/ordersettinglist/confirm.do",row).then((resp)=>{
                        if (resp.data.flag){
                            this.$message.success(resp.data.message);
                        } else
                            this.$message.error(resp.data.message);
                    }).catch((error)=>{
                        console.log(error);
                    }).finally(()=>{
                        this.findPage();
                    })
                },
                //切换页码
                handleCurrentChange(currentPage){
                    //设置最新的页码
                    this.pagination.currentPage=currentPage;
                    //重新调用findPage方法进行分页查询
                    this.findPage();
                },
                //切换显示行数
                handleSizeChange(pageSize){
                    //设置最新的当前页显示行数
                    this.pagination.pageSize=pageSize;
                    //重新调用findPage方法进行分页查询
                    this.findPage();
                },
                //切换套餐显示页码
                setmealHandleCurrentChange(currentPage){
                    //设置最新的页码
                    this.setmeal_pagination.currentPage=currentPage;
                    //重新调用findPage方法进行分页查询
                    this.findSetmeal();
                },
                //切换套餐显示行数
                setmealHandleSizeChange(pageSize){
                    //设置最新的当前页显示行数
                    this.setmeal_pagination.pageSize=pageSize;
                    //重新调用findPage方法进行分页查询
                    this.findSetmeal();
                },
                //获取当前表格中被选中的行对象
                chooseRow(row){
                    //取出这个套餐对象的id
                    this.setmealId = row.id;
                },
                //获取当前表格中被选中的行对象
                changeChooseRow(currentRow){
                    //取出这个套餐对象的id
                    this.setmealId = currentRow.id;
                },
                handleSelectionChange(row){
                    this.orders=row;
                },
                // 删除
                handleDelete(row) {
                    //删除动作较为危险,应给予用户一个删除提示,防止用户误触
                    this.$confirm('此操作将永久删除该条记录, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //then表示用户选择了'确定',则向后台发送当前行的id,执行删除动作
                        axios.post("/ordersettinglist/delete.do",row).then((resp)=>{
                            if (resp.data.flag){
                                this.$message.success(resp.data.message);
                            } else
                                this.$message.error(resp.data.message);
                        }).catch((error)=>{
                            console.log(error);
                            this.showMessage(error);
                        }).finally(()=>{
                            this.findPage();
                        })
                    }).catch(() => {
                        //catch表示用户选择了'取消',弹出提示信息
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                },
                showMessage(r){
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                },
                handleDeleteSelection(){
                    //删除动作较为危险,应给予用户一个删除提示,防止用户误触
                    this.$confirm('此操作将永久删除该条记录, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //then表示用户选择了'确定',则向后台发送当前行的id,执行删除动作
                        axios.post("/ordersettinglist/deleteSelection.do",this.orders).then((resp)=>{
                            if (resp.data.flag){
                                this.$message.success(resp.data.message);
                            } else
                                this.$message.error(resp.data.message);
                        }).catch((error)=>{
                            console.log(error);
                            this.showMessage(error);
                        }).finally(()=>{
                            this.findPage();
                        })
                    }).catch(() => {
                        //catch表示用户选择了'取消',弹出提示信息
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                }
            }
        })
    </script>
</html>